package com.xiaoxin.dubbo.api;

import com.xiaoxin.model.mongo.FocusUser;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

/**
 * @author xiaoxiaode
 * @date 2021/9/12 22:25
 **/

@DubboService
public class focusUserApiImpl implements  focusUserApi {


    @Autowired
    private MongoTemplate mongoTemplate;


    public void save(FocusUser focusUser) {
        focusUser.setCreated(System.currentTimeMillis());
        mongoTemplate.save(focusUser);
    }

    @Override
    public void delete(FocusUser focusUser) {
        Query query=Query.query(Criteria.where("userId")
                .is(focusUser.getUserId())
                .and("followUserId").is(focusUser.getFollowUserId()));
        mongoTemplate.remove(query,FocusUser.class);
    }
}
